﻿using System;

namespace MudEngine.Parsing
{
	[Flags]
	public enum Modifier
	{
		@new = 0x0001,
		@public = 0x0002,
		@private = 0x0004,
		@static = 0x0008,
		@readonly = 0x0010,

		none = 0x0000,
		all = @new | @public | @private | @static | @readonly
	}

	public class Modifiers
	{
		private Modifier cur = Modifier.none;
		private Parser parser;

		public Modifiers(Parser parser)
		{
			this.parser = parser;
		}

		public void Add(Modifier m)
		{
			if ((cur & m) == 0)
				cur |= m;
			else
				parser.SemErr("modifier " + m + " already defined");
		}

		public void Add(Modifiers m) { Add(m.cur); }

		public bool IsNone { get { return cur == Modifier.none; } }

		public void Check(Modifier allowed)
		{
			Modifier wrong = cur & (allowed ^ Modifier.all);
			if (wrong != Modifier.none)
				parser.SemErr("modifier(s) " + wrong + " not allowed here");
		}
	}
}
